<?php

namespace App\Http\Services;

use App\Models\Lecturer;
use App\Models\LecturerClass;
use Auth;
use Illuminate\Database\Eloquent\Model;

class TaskService
{
    public function update($item)
    {
        $data = new Lecturer();
        if(isset($item['id']) && $item['id'] > 0){
            $data = Lecturer::find($item['id']);
            if(!$data){
                return false;
            }
        }else{
            $data->create_time = time();
        }

        $data->address = $item['address'] ?? '';
        $data->course_num = $item['course_num'] ?? 0;
        $data->course_outline = $item['course_outline'] ?? '';
        $data->face_img = $item['face_img'] ?? '';
        $data->info = $item['info'] ?? '';
        $data->is_recommend = $item['is_recommend'] ?? 0;
        $data->master = $item['master'] ?? '';
        $data->name = $item['name'] ?? '';
        $data->post = $item['post'] ?? '';
        $data->sid = $item['sid'] ?? 0;
        $data->cid = $item['cid'] ?? 0;
        $data->synopsis = $item['synopsis'] ?? '';
        $data->update_time = time();
        $data->save();
        if($data->id){
            return true;
        }
        return  false;
    }

    public function typeUpdate($item)
    {
        $data = new LecturerClass();
        if(isset($item['id']) && $item['id'] > 0){
            $data = LecturerClass::find($item['id']);
            if(!$data){
                return false;
            }
        }else{
            $data->create_time = time();
        }

        $data->title = $item['title'];
        $data->sid = $item['sid'] ?? 0;
        $data->update_time = time();
        $data->save();
        if($data->id){
            return true;
        }
        return  false;
    }
    
    
}
